﻿#include "stm32regs.h"
#include "stm32regbit.h"
extern void SystemClock_Config(void);
/*
 * main.c
 *
 *  Created on: 2020-12-12
 *      Author: pengdan
 */
int xx = 0xffff;
int yy = 0x22;
int zz = 0x33;

void led_config(void)
{
	u32 tmpreg;
	//设置时钟
	/* Delay after an RCC peripheral clock enabling */
	SET_BIT(RCC->AHB2ENR, RCC_AHB2SMENR_GPIOASMEN_Msk);
	tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2SMENR_GPIOASMEN_Msk);
	(void)(tmpreg);
	WRITE_REG(GPIOA->BRR, GPIO_BSRR_BS5);

/* Initialize  pinpos on first pin set */
//pinpos = POSITION_VAL(GPIO_BSRR_BS5);
#if 1
	//设置模式
	/*MODIFY_REG(GPIOA->MODER, (GPIO_MODER_MODE0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U)),\
						 (GPIO_MODER_MODE0_0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U))); */
	GPIOA->MODER &= ~(3 << GPIO_BSRR_BS5_Pos * 2U);
	GPIOA->MODER |= (1 << GPIO_BSRR_BS5_Pos * 2U);
	//设置速度
	/*MODIFY_REG(GPIOA->OSPEEDR, (GPIO_OSPEEDR_OSPEED0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U)),\
						 (GPIO_OSPEEDR_OSPEED0_0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U)));*/
	GPIOA->OSPEEDR &= ~(3 << GPIO_BSRR_BS5_Pos * 2U);
	GPIOA->OSPEEDR |= (0 << GPIO_BSRR_BS5_Pos * 2U);
	//设置上下拉
	/*MODIFY_REG(GPIOA->PUPDR, (GPIO_PUPDR_PUPD0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U)),\
						 (0 << (POSITION_VAL(GPIO_BSRR_BS5) * 2U)));*/
	GPIOA->PUPDR &= ~(3 << GPIO_BSRR_BS5_Pos * 2U);
	GPIOA->PUPDR |= (0 << GPIO_BSRR_BS5_Pos * 2U);
	//设置输出模式  推挽
	MODIFY_REG(GPIOA->OTYPER, GPIO_BSRR_BS5, (GPIO_BSRR_BS5 * 0));

	WRITE_REG(GPIOA->BSRR, GPIO_BSRR_BS5);
#endif
}

void led_control(u8 status)
{
	if (status)
	{
		WRITE_REG(GPIOA->BSRR, GPIO_BSRR_BS5);
	}
<<<<<<< HEAD
<<<<<<< HEAD

=======
>>>>>>> 9660d21961486f27993203ebbb0dbc5fe7e22eca
=======
>>>>>>> 9660d21961486f27993203ebbb0dbc5fe7e22eca
	else
	{
		WRITE_REG(GPIOA->BRR, GPIO_BSRR_BS5);
	}
}
struct
{
	int x;
	int y;
	int z;
} peng;

int main(void)
{
	//SystemClock_Config();
	led_config();
	led_control(1);
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> 9660d21961486f27993203ebbb0dbc5fe7e22eca
	xx = 0xfffff;
	yy = 0x22;
	zz = 0x33;
>>>>>>> 9660d21961486f27993203ebbb0dbc5fe7e22eca

	peng.x = 0x11;
	peng.y = 0x22;
	peng.z = 0x33;
	while (1)
	{
		if (yy)
		{
			led_control(1);
			yy -= 1;
			if (!yy)
			{
				zz = xx;
			}
		}
		else
		{
			if (zz)
			{
				zz -= 1;
				if (!zz)
				{
					yy = xx;
				}
				led_control(0);
			}
		}
	}
	return 0;
}